package conf2.net;

import java.io.Serializable;

public class Message implements Serializable {

    public enum Type {

        NAME,
        GAME_INFO,
        PLACEMENT,
        PEER_IS_DISCONNECTING,
        NUMBER_OF_SPECIAL_CARDS,
        SPECIAL_CARD_SELECTION,

        MOVE
    }
    private final Object data;
    private final Type type;
    private final String className,  methodName;
    private final int lineNr;

    public boolean dataIsOfClass(Class c) {
        return data.getClass().equals(c);
    }

    public Message(Type type, Object data) {
        this.data = data;
        this.type = type;
        Throwable th = new Throwable();
        StackTraceElement elem = th.getStackTrace()[1];
        className = elem.getClassName();
        methodName = elem.getMethodName();
        lineNr = elem.getLineNumber();
    }

    public String getCreatorClassName() {
        return className;
    }

    public String getCreatorMethodName() {
        return methodName;
    }

    public int getCreatorLineNr() {
        return lineNr;
    }

    public Object getData() {
        return data;
    }

    public Type getType() {
        return type;
    }

    @Override
    public String toString() {
        return type + ":" + data;
    }
}
